<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Voro++: pre_container.cc Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Voro++
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript" src="dynsections.js"></script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">pre_container.cc</div>  </div>
</div>
<div class="contents">
<a href="pre__container_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Voro++, a 3D cell-based Voronoi library</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// Author   : Chris H. Rycroft (LBL / UC Berkeley)</span>
<a name="l00004"></a>00004 <span class="comment">// Email    : chr@alum.mit.edu</span>
<a name="l00005"></a>00005 <span class="comment">// Date     : August 30th 2011</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment">/** \file pre_container.cc</span>
<a name="l00008"></a>00008 <span class="comment"> * \brief Function implementations for the pre_container and related classes.</span>
<a name="l00009"></a>00009 <span class="comment"> */</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;cstdio&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;cmath&gt;</span>
<a name="l00013"></a>00013 <span class="keyword">using namespace </span>std;
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="preprocessor">#include &quot;<a class="code" href="config_8hh.html" title="Master configuration file for setting various compile-time options.">config.hh</a>&quot;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;<a class="code" href="pre__container_8hh.html" title="Header file for the pre_container and related classes.">pre_container.hh</a>&quot;</span>
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 <span class="keyword">namespace </span>voro {
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="comment">/** The class constructor sets up the geometry of container, initializing the</span>
<a name="l00021"></a>00021 <span class="comment"> * minimum and maximum coordinates in each direction. It allocates an initial</span>
<a name="l00022"></a>00022 <span class="comment"> * chunk into which to store particle information.</span>
<a name="l00023"></a>00023 <span class="comment"> * \param[in] (ax_,bx_) the minimum and maximum x coordinates.</span>
<a name="l00024"></a>00024 <span class="comment"> * \param[in] (ay_,by_) the minimum and maximum y coordinates.</span>
<a name="l00025"></a>00025 <span class="comment"> * \param[in] (az_,bz_) the minimum and maximum z coordinates.</span>
<a name="l00026"></a>00026 <span class="comment"> * \param[in] (xperiodic_,yperiodic_,zperiodic_ ) flags setting whether the</span>
<a name="l00027"></a>00027 <span class="comment"> *                                                container is periodic in each</span>
<a name="l00028"></a>00028 <span class="comment"> *                                                coordinate direction.</span>
<a name="l00029"></a>00029 <span class="comment"> * \param[in] ps_ the number of floating point entries to store for each</span>
<a name="l00030"></a>00030 <span class="comment"> *                particle. */</span>
<a name="l00031"></a><a class="code" href="classvoro_1_1pre__container__base.html#a522bd57b4a0e4af6b197c04d103adc68">00031</a> pre_container_base::pre_container_base(<span class="keywordtype">double</span> ax_,<span class="keywordtype">double</span> bx_,<span class="keywordtype">double</span> ay_,<span class="keywordtype">double</span> by_,<span class="keywordtype">double</span> az_,<span class="keywordtype">double</span> bz_,
<a name="l00032"></a>00032         <span class="keywordtype">bool</span> xperiodic_,<span class="keywordtype">bool</span> yperiodic_,<span class="keywordtype">bool</span> zperiodic_,<span class="keywordtype">int</span> ps_) :
<a name="l00033"></a>00033         ax(ax_), bx(bx_), ay(ay_), by(by_), az(az_), bz(bz_),
<a name="l00034"></a>00034         xperiodic(xperiodic_), yperiodic(yperiodic_), zperiodic(zperiodic_), ps(ps_),
<a name="l00035"></a>00035         index_sz(init_chunk_size), pre_id(new int*[index_sz]), end_id(pre_id),
<a name="l00036"></a>00036         pre_p(new double*[index_sz]), end_p(pre_p) {
<a name="l00037"></a>00037                 <a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>=*<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>=<span class="keyword">new</span> <span class="keywordtype">int</span>[pre_container_chunk_size];
<a name="l00038"></a>00038                 <a class="code" href="classvoro_1_1pre__container__base.html#a49cb1c584f78ac8fdce353fd2f43b5f6">l_id</a>=<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>+<a class="code" href="classvoro_1_1pre__container__base.html#a9ae49ab1c51dc851e7ddf3035b719a6b">index_sz</a>;<a class="code" href="classvoro_1_1pre__container__base.html#a73bcad154008325e074bea734fc4125b">e_id</a>=<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>+pre_container_chunk_size;
<a name="l00039"></a>00039                 <a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>=*<a class="code" href="classvoro_1_1pre__container__base.html#ae4dc10b744019a92efffbcc1ece189e4">end_p</a>=<span class="keyword">new</span> <span class="keywordtype">double</span>[<a class="code" href="classvoro_1_1pre__container__base.html#a4a3ff1d6bee289e53f5015327384444a">ps</a>*pre_container_chunk_size];
<a name="l00040"></a>00040 }
<a name="l00041"></a>00041 <span class="comment"></span>
<a name="l00042"></a>00042 <span class="comment">/** The destructor frees the dynamically allocated memory. */</span>
<a name="l00043"></a><a class="code" href="classvoro_1_1pre__container__base.html#a9832a92c7e6dbc2959ab958ea821ca9a">00043</a> <a class="code" href="classvoro_1_1pre__container__base.html#a9832a92c7e6dbc2959ab958ea821ca9a">pre_container_base::~pre_container_base</a>() {
<a name="l00044"></a>00044         <span class="keyword">delete</span> [] *<a class="code" href="classvoro_1_1pre__container__base.html#ae4dc10b744019a92efffbcc1ece189e4">end_p</a>;
<a name="l00045"></a>00045         <span class="keyword">delete</span> [] *<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>;
<a name="l00046"></a>00046         <span class="keywordflow">while</span> (<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>!=<a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>) {
<a name="l00047"></a>00047                 <a class="code" href="classvoro_1_1pre__container__base.html#ae4dc10b744019a92efffbcc1ece189e4">end_p</a>--;
<a name="l00048"></a>00048                 <span class="keyword">delete</span> [] *<a class="code" href="classvoro_1_1pre__container__base.html#ae4dc10b744019a92efffbcc1ece189e4">end_p</a>;
<a name="l00049"></a>00049                 <a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>--;
<a name="l00050"></a>00050                 <span class="keyword">delete</span> [] *<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>;
<a name="l00051"></a>00051         }
<a name="l00052"></a>00052         <span class="keyword">delete</span> [] <a class="code" href="classvoro_1_1pre__container__base.html#a8f3fadf0d9d115fec92eedbcb2c5af9c">pre_p</a>;
<a name="l00053"></a>00053         <span class="keyword">delete</span> [] <a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>;
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 <span class="comment"></span>
<a name="l00056"></a>00056 <span class="comment">/** Makes a guess at the optimal grid of blocks to use, computing in</span>
<a name="l00057"></a>00057 <span class="comment"> * a way that</span>
<a name="l00058"></a>00058 <span class="comment"> * \param[out] (nx,ny,nz) the number of blocks to use. */</span>
<a name="l00059"></a><a class="code" href="classvoro_1_1pre__container__base.html#a8e1fcadbeedc63f205a36c2fa9333ab6">00059</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container__base.html#a8e1fcadbeedc63f205a36c2fa9333ab6">pre_container_base::guess_optimal</a>(<span class="keywordtype">int</span> &amp;nx,<span class="keywordtype">int</span> &amp;ny,<span class="keywordtype">int</span> &amp;nz) {
<a name="l00060"></a>00060         <span class="keywordtype">double</span> dx(<a class="code" href="classvoro_1_1pre__container__base.html#a34dfa63f38cf870b32004e12558463a0">bx</a>-<a class="code" href="classvoro_1_1pre__container__base.html#a7ffde3944d0899b6ae9abe42e6567789">ax</a>),dy(<a class="code" href="classvoro_1_1pre__container__base.html#a6acac844ab71a02ea6a990fccdbd5c59">by</a>-<a class="code" href="classvoro_1_1pre__container__base.html#a397c0ae141594e1868eb6248a6d57d52">ay</a>),dz(<a class="code" href="classvoro_1_1pre__container__base.html#a9049eaba232b13aa3a9562dffa57bc24">bz</a>-<a class="code" href="classvoro_1_1pre__container__base.html#a68952c93198e0623604a049aa4140d52">az</a>);
<a name="l00061"></a>00061         <span class="keywordtype">double</span> ilscale(pow(<a class="code" href="classvoro_1_1pre__container__base.html#a253ea1bdfa1b82c3fb0ab12f1685d695">total_particles</a>()/(optimal_particles*dx*dy*dz),1/3.0));
<a name="l00062"></a>00062         nx=int(dx*ilscale+1);
<a name="l00063"></a>00063         ny=int(dy*ilscale+1);
<a name="l00064"></a>00064         nz=int(dz*ilscale+1);
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066 <span class="comment"></span>
<a name="l00067"></a>00067 <span class="comment">/** Stores a particle ID and position, allocating a new memory chunk if</span>
<a name="l00068"></a>00068 <span class="comment"> * necessary. For coordinate directions in which the container is not periodic,</span>
<a name="l00069"></a>00069 <span class="comment"> * the routine checks to make sure that the particle is within the container</span>
<a name="l00070"></a>00070 <span class="comment"> * bounds. If the particle is out of bounds, it is not stored.</span>
<a name="l00071"></a>00071 <span class="comment"> * \param[in] n the numerical ID of the inserted particle.</span>
<a name="l00072"></a>00072 <span class="comment"> * \param[in] (x,y,z) the position vector of the inserted particle. */</span>
<a name="l00073"></a><a class="code" href="classvoro_1_1pre__container.html#ac68ce0449cf83ee282325d5302ffa4cd">00073</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container.html#ac68ce0449cf83ee282325d5302ffa4cd">pre_container::put</a>(<span class="keywordtype">int</span> n,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00074"></a>00074         <span class="keywordflow">if</span>((<a class="code" href="classvoro_1_1pre__container__base.html#aa7cffdaee881f941e421d0e9e3f38db3">xperiodic</a>||(x&gt;=<a class="code" href="classvoro_1_1pre__container__base.html#a7ffde3944d0899b6ae9abe42e6567789">ax</a>&amp;&amp;x&lt;=<a class="code" href="classvoro_1_1pre__container__base.html#a34dfa63f38cf870b32004e12558463a0">bx</a>))&amp;&amp;(<a class="code" href="classvoro_1_1pre__container__base.html#aa86a0e8ac0bafbc2bf2fefbafce005be">yperiodic</a>||(y&gt;=<a class="code" href="classvoro_1_1pre__container__base.html#a397c0ae141594e1868eb6248a6d57d52">ay</a>&amp;&amp;y&lt;=<a class="code" href="classvoro_1_1pre__container__base.html#a6acac844ab71a02ea6a990fccdbd5c59">by</a>))&amp;&amp;(<a class="code" href="classvoro_1_1pre__container__base.html#a5df09b1ba1e3fe49c3efba11ed44efb2">zperiodic</a>||(z&gt;=<a class="code" href="classvoro_1_1pre__container__base.html#a68952c93198e0623604a049aa4140d52">az</a>&amp;&amp;z&lt;=<a class="code" href="classvoro_1_1pre__container__base.html#a9049eaba232b13aa3a9562dffa57bc24">bz</a>))) {
<a name="l00075"></a>00075                 <span class="keywordflow">if</span>(<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>==<a class="code" href="classvoro_1_1pre__container__base.html#a73bcad154008325e074bea734fc4125b">e_id</a>) <a class="code" href="classvoro_1_1pre__container__base.html#a3b9e5b59a4fd8477321d9412feffac4f">new_chunk</a>();
<a name="l00076"></a>00076                 *(<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>++)=n;
<a name="l00077"></a>00077                 *(<a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>++)=x;*(<a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>++)=y;*(<a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>++)=z;
<a name="l00078"></a>00078         }
<a name="l00079"></a>00079 <span class="preprocessor">#if VOROPP_REPORT_OUT_OF_BOUNDS ==1</span>
<a name="l00080"></a>00080 <span class="preprocessor"></span>        <span class="keywordflow">else</span> fprintf(stderr,<span class="stringliteral">&quot;Out of bounds: (x,y,z)=(%g,%g,%g)\n&quot;</span>,x,y,z);
<a name="l00081"></a>00081 <span class="preprocessor">#endif</span>
<a name="l00082"></a>00082 <span class="preprocessor"></span>}
<a name="l00083"></a>00083 <span class="comment"></span>
<a name="l00084"></a>00084 <span class="comment">/** Stores a particle ID and position, allocating a new memory chunk if necessary.</span>
<a name="l00085"></a>00085 <span class="comment"> * \param[in] n the numerical ID of the inserted particle.</span>
<a name="l00086"></a>00086 <span class="comment"> * \param[in] (x,y,z) the position vector of the inserted particle.</span>
<a name="l00087"></a>00087 <span class="comment"> * \param[in] r the radius of the particle. */</span>
<a name="l00088"></a><a class="code" href="classvoro_1_1pre__container__poly.html#abc5d9009deec44c1f5fc88e4da10e89a">00088</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container__poly.html#abc5d9009deec44c1f5fc88e4da10e89a">pre_container_poly::put</a>(<span class="keywordtype">int</span> n,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z,<span class="keywordtype">double</span> r) {
<a name="l00089"></a>00089         <span class="keywordflow">if</span>((<a class="code" href="classvoro_1_1pre__container__base.html#aa7cffdaee881f941e421d0e9e3f38db3">xperiodic</a>||(x&gt;=<a class="code" href="classvoro_1_1pre__container__base.html#a7ffde3944d0899b6ae9abe42e6567789">ax</a>&amp;&amp;x&lt;=<a class="code" href="classvoro_1_1pre__container__base.html#a34dfa63f38cf870b32004e12558463a0">bx</a>))&amp;&amp;(<a class="code" href="classvoro_1_1pre__container__base.html#aa86a0e8ac0bafbc2bf2fefbafce005be">yperiodic</a>||(y&gt;=<a class="code" href="classvoro_1_1pre__container__base.html#a397c0ae141594e1868eb6248a6d57d52">ay</a>&amp;&amp;y&lt;=<a class="code" href="classvoro_1_1pre__container__base.html#a6acac844ab71a02ea6a990fccdbd5c59">by</a>))&amp;&amp;(<a class="code" href="classvoro_1_1pre__container__base.html#a5df09b1ba1e3fe49c3efba11ed44efb2">zperiodic</a>||(z&gt;=<a class="code" href="classvoro_1_1pre__container__base.html#a68952c93198e0623604a049aa4140d52">az</a>&amp;&amp;z&lt;=<a class="code" href="classvoro_1_1pre__container__base.html#a9049eaba232b13aa3a9562dffa57bc24">bz</a>))) {
<a name="l00090"></a>00090                 <span class="keywordflow">if</span>(<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>==<a class="code" href="classvoro_1_1pre__container__base.html#a73bcad154008325e074bea734fc4125b">e_id</a>) <a class="code" href="classvoro_1_1pre__container__base.html#a3b9e5b59a4fd8477321d9412feffac4f">new_chunk</a>();
<a name="l00091"></a>00091                 *(<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>++)=n;
<a name="l00092"></a>00092                 *(<a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>++)=x;*(<a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>++)=y;*(<a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>++)=z;*(<a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>++)=r;
<a name="l00093"></a>00093         }
<a name="l00094"></a>00094 <span class="preprocessor">#if VOROPP_REPORT_OUT_OF_BOUNDS ==1</span>
<a name="l00095"></a>00095 <span class="preprocessor"></span>        <span class="keywordflow">else</span> fprintf(stderr,<span class="stringliteral">&quot;Out of bounds: (x,y,z)=(%g,%g,%g)\n&quot;</span>,x,y,z);
<a name="l00096"></a>00096 <span class="preprocessor">#endif</span>
<a name="l00097"></a>00097 <span class="preprocessor"></span>}
<a name="l00098"></a>00098 <span class="comment"></span>
<a name="l00099"></a>00099 <span class="comment">/** Transfers the particles stored within the class to a container class.</span>
<a name="l00100"></a>00100 <span class="comment"> * \param[in] con the container class to transfer to. */</span>
<a name="l00101"></a><a class="code" href="classvoro_1_1pre__container.html#a7a2e73ad34fbfe1001f59ea3b69f992f">00101</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container.html#a7a2e73ad34fbfe1001f59ea3b69f992f">pre_container::setup</a>(<a class="code" href="classvoro_1_1container.html" title="Extension of the container_base class for computing regular Voronoi tessellations.">container</a> &amp;con) {
<a name="l00102"></a>00102         <span class="keywordtype">int</span> **c_id=<a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>,*idp,*ide,n;
<a name="l00103"></a>00103         <span class="keywordtype">double</span> **c_p=<a class="code" href="classvoro_1_1pre__container__base.html#a8f3fadf0d9d115fec92eedbcb2c5af9c">pre_p</a>,*pp,x,y,z;
<a name="l00104"></a>00104         <span class="keywordflow">while</span>(c_id&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>) {
<a name="l00105"></a>00105                 idp=*(c_id++);ide=idp+pre_container_chunk_size;
<a name="l00106"></a>00106                 pp=*(c_p++);
<a name="l00107"></a>00107                 <span class="keywordflow">while</span>(idp&lt;ide) {
<a name="l00108"></a>00108                         n=*(idp++);x=*(pp++);y=*(pp++);z=*(pp++);
<a name="l00109"></a>00109                         con.<a class="code" href="classvoro_1_1container.html#a5c67c9998e4f174fb217967dcb41c7f3">put</a>(n,x,y,z);
<a name="l00110"></a>00110                 }
<a name="l00111"></a>00111         }
<a name="l00112"></a>00112         idp=*c_id;
<a name="l00113"></a>00113         pp=*c_p;
<a name="l00114"></a>00114         <span class="keywordflow">while</span>(idp&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>) {
<a name="l00115"></a>00115                 n=*(idp++);x=*(pp++);y=*(pp++);z=*(pp++);
<a name="l00116"></a>00116                 con.<a class="code" href="classvoro_1_1container.html#a5c67c9998e4f174fb217967dcb41c7f3">put</a>(n,x,y,z);
<a name="l00117"></a>00117         }
<a name="l00118"></a>00118 }
<a name="l00119"></a>00119 <span class="comment"></span>
<a name="l00120"></a>00120 <span class="comment">/** Transfers the particles stored within the class to a container_poly class.</span>
<a name="l00121"></a>00121 <span class="comment"> * \param[in] con the container_poly class to transfer to. */</span>
<a name="l00122"></a><a class="code" href="classvoro_1_1pre__container__poly.html#ac71c0ee24182a115ce79da4cc91ee356">00122</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container__poly.html#ac71c0ee24182a115ce79da4cc91ee356">pre_container_poly::setup</a>(<a class="code" href="classvoro_1_1container__poly.html" title="Extension of the container_base class for computing radical Voronoi tessellations.">container_poly</a> &amp;con) {
<a name="l00123"></a>00123         <span class="keywordtype">int</span> **c_id=<a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>,*idp,*ide,n;
<a name="l00124"></a>00124         <span class="keywordtype">double</span> **c_p=<a class="code" href="classvoro_1_1pre__container__base.html#a8f3fadf0d9d115fec92eedbcb2c5af9c">pre_p</a>,*pp,x,y,z,r;
<a name="l00125"></a>00125         <span class="keywordflow">while</span>(c_id&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>) {
<a name="l00126"></a>00126                 idp=*(c_id++);ide=idp+pre_container_chunk_size;
<a name="l00127"></a>00127                 pp=*(c_p++);
<a name="l00128"></a>00128                 <span class="keywordflow">while</span>(idp&lt;ide) {
<a name="l00129"></a>00129                         n=*(idp++);x=*(pp++);y=*(pp++);z=*(pp++);r=*(pp++);
<a name="l00130"></a>00130                         con.<a class="code" href="classvoro_1_1container__poly.html#a61689312fb6f8ee36f1fbb0fe00e4fe3">put</a>(n,x,y,z,r);
<a name="l00131"></a>00131                 }
<a name="l00132"></a>00132         }
<a name="l00133"></a>00133         idp=*c_id;
<a name="l00134"></a>00134         pp=*c_p;
<a name="l00135"></a>00135         <span class="keywordflow">while</span>(idp&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>) {
<a name="l00136"></a>00136                 n=*(idp++);x=*(pp++);y=*(pp++);z=*(pp++);r=*(pp++);
<a name="l00137"></a>00137                 con.<a class="code" href="classvoro_1_1container__poly.html#a61689312fb6f8ee36f1fbb0fe00e4fe3">put</a>(n,x,y,z,r);
<a name="l00138"></a>00138         }
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 <span class="comment"></span>
<a name="l00141"></a>00141 <span class="comment">/** Transfers the particles stored within the class to a container class, also</span>
<a name="l00142"></a>00142 <span class="comment"> * recording the order in which particles were stored.</span>
<a name="l00143"></a>00143 <span class="comment"> * \param[in] vo the ordering class to use.</span>
<a name="l00144"></a>00144 <span class="comment"> * \param[in] con the container class to transfer to. */</span>
<a name="l00145"></a><a class="code" href="classvoro_1_1pre__container.html#a81aae000e3b787c58deef7a8f197bdc3">00145</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container.html#a7a2e73ad34fbfe1001f59ea3b69f992f">pre_container::setup</a>(<a class="code" href="classvoro_1_1particle__order.html" title="A class for storing ordering information when particles are added to a container.">particle_order</a> &amp;vo,<a class="code" href="classvoro_1_1container.html" title="Extension of the container_base class for computing regular Voronoi tessellations.">container</a> &amp;con) {
<a name="l00146"></a>00146         <span class="keywordtype">int</span> **c_id=<a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>,*idp,*ide,n;
<a name="l00147"></a>00147         <span class="keywordtype">double</span> **c_p=<a class="code" href="classvoro_1_1pre__container__base.html#a8f3fadf0d9d115fec92eedbcb2c5af9c">pre_p</a>,*pp,x,y,z;
<a name="l00148"></a>00148         <span class="keywordflow">while</span>(c_id&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>) {
<a name="l00149"></a>00149                 idp=*(c_id++);ide=idp+pre_container_chunk_size;
<a name="l00150"></a>00150                 pp=*(c_p++);
<a name="l00151"></a>00151                 <span class="keywordflow">while</span>(idp&lt;ide) {
<a name="l00152"></a>00152                         n=*(idp++);x=*(pp++);y=*(pp++);z=*(pp++);
<a name="l00153"></a>00153                         con.<a class="code" href="classvoro_1_1container.html#a5c67c9998e4f174fb217967dcb41c7f3">put</a>(vo,n,x,y,z);
<a name="l00154"></a>00154                 }
<a name="l00155"></a>00155         }
<a name="l00156"></a>00156         idp=*c_id;
<a name="l00157"></a>00157         pp=*c_p;
<a name="l00158"></a>00158         <span class="keywordflow">while</span>(idp&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>) {
<a name="l00159"></a>00159                 n=*(idp++);x=*(pp++);y=*(pp++);z=*(pp++);
<a name="l00160"></a>00160                 con.<a class="code" href="classvoro_1_1container.html#a5c67c9998e4f174fb217967dcb41c7f3">put</a>(vo,n,x,y,z);
<a name="l00161"></a>00161         }
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163 <span class="comment"></span>
<a name="l00164"></a>00164 <span class="comment">/** Transfers the particles stored within the class to a container_poly class,</span>
<a name="l00165"></a>00165 <span class="comment"> * also recording the order in which particles were stored.</span>
<a name="l00166"></a>00166 <span class="comment"> * \param[in] vo the ordering class to use.</span>
<a name="l00167"></a>00167 <span class="comment"> * \param[in] con the container_poly class to transfer to. */</span>
<a name="l00168"></a><a class="code" href="classvoro_1_1pre__container__poly.html#ac18d16204c7769ec554d14f84b6517f0">00168</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container__poly.html#ac71c0ee24182a115ce79da4cc91ee356">pre_container_poly::setup</a>(<a class="code" href="classvoro_1_1particle__order.html" title="A class for storing ordering information when particles are added to a container.">particle_order</a> &amp;vo,<a class="code" href="classvoro_1_1container__poly.html" title="Extension of the container_base class for computing radical Voronoi tessellations.">container_poly</a> &amp;con) {
<a name="l00169"></a>00169         <span class="keywordtype">int</span> **c_id=<a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>,*idp,*ide,n;
<a name="l00170"></a>00170         <span class="keywordtype">double</span> **c_p=<a class="code" href="classvoro_1_1pre__container__base.html#a8f3fadf0d9d115fec92eedbcb2c5af9c">pre_p</a>,*pp,x,y,z,r;
<a name="l00171"></a>00171         <span class="keywordflow">while</span>(c_id&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>) {
<a name="l00172"></a>00172                 idp=*(c_id++);ide=idp+pre_container_chunk_size;
<a name="l00173"></a>00173                 pp=*(c_p++);
<a name="l00174"></a>00174                 <span class="keywordflow">while</span>(idp&lt;ide) {
<a name="l00175"></a>00175                         n=*(idp++);x=*(pp++);y=*(pp++);z=*(pp++);r=*(pp++);
<a name="l00176"></a>00176                         con.<a class="code" href="classvoro_1_1container__poly.html#a61689312fb6f8ee36f1fbb0fe00e4fe3">put</a>(vo,n,x,y,z,r);
<a name="l00177"></a>00177                 }
<a name="l00178"></a>00178         }
<a name="l00179"></a>00179         idp=*c_id;
<a name="l00180"></a>00180         pp=*c_p;
<a name="l00181"></a>00181         <span class="keywordflow">while</span>(idp&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>) {
<a name="l00182"></a>00182                 n=*(idp++);x=*(pp++);y=*(pp++);z=*(pp++);r=*(pp++);
<a name="l00183"></a>00183                 con.<a class="code" href="classvoro_1_1container__poly.html#a61689312fb6f8ee36f1fbb0fe00e4fe3">put</a>(vo,n,x,y,z,r);
<a name="l00184"></a>00184         }
<a name="l00185"></a>00185 }
<a name="l00186"></a>00186 <span class="comment"></span>
<a name="l00187"></a>00187 <span class="comment">/** Import a list of particles from an open file stream into the container.</span>
<a name="l00188"></a>00188 <span class="comment"> * Entries of four numbers (Particle ID, x position, y position, z position)</span>
<a name="l00189"></a>00189 <span class="comment"> * are searched for. If the file cannot be successfully read, then the routine</span>
<a name="l00190"></a>00190 <span class="comment"> * causes a fatal error.</span>
<a name="l00191"></a>00191 <span class="comment"> * \param[in] fp the file handle to read from. */</span>
<a name="l00192"></a><a class="code" href="classvoro_1_1pre__container.html#a0d62168ad0379672e038ec07cc362567">00192</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container.html#a0d62168ad0379672e038ec07cc362567">pre_container::import</a>(FILE *fp) {
<a name="l00193"></a>00193         <span class="keywordtype">int</span> i,j;
<a name="l00194"></a>00194         <span class="keywordtype">double</span> x,y,z;
<a name="l00195"></a>00195         <span class="keywordflow">while</span>((j=fscanf(fp,<span class="stringliteral">&quot;%d %lg %lg %lg&quot;</span>,&amp;i,&amp;x,&amp;y,&amp;z))==4) <a class="code" href="classvoro_1_1pre__container.html#ac68ce0449cf83ee282325d5302ffa4cd">put</a>(i,x,y,z);
<a name="l00196"></a>00196         <span class="keywordflow">if</span>(j!=EOF) voro_fatal_error(<span class="stringliteral">&quot;File import error&quot;</span>,<a class="code" href="config_8hh.html#a8de7f106cac2556a67bcc61bd364ed38">VOROPP_FILE_ERROR</a>);
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198 <span class="comment"></span>
<a name="l00199"></a>00199 <span class="comment">/** Import a list of particles from an open file stream, also storing the order</span>
<a name="l00200"></a>00200 <span class="comment"> * of that the particles are read. Entries of four numbers (Particle ID, x</span>
<a name="l00201"></a>00201 <span class="comment"> * position, y position, z position) are searched for. If the file cannot be</span>
<a name="l00202"></a>00202 <span class="comment"> * successfully read, then the routine causes a fatal error.</span>
<a name="l00203"></a>00203 <span class="comment"> * \param[in] fp the file handle to read from. */</span>
<a name="l00204"></a><a class="code" href="classvoro_1_1pre__container__poly.html#aa6aab61ad68e90a513e53433313c2a4a">00204</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container__poly.html#aa6aab61ad68e90a513e53433313c2a4a">pre_container_poly::import</a>(FILE *fp) {
<a name="l00205"></a>00205         <span class="keywordtype">int</span> i,j;
<a name="l00206"></a>00206         <span class="keywordtype">double</span> x,y,z,r;
<a name="l00207"></a>00207         <span class="keywordflow">while</span>((j=fscanf(fp,<span class="stringliteral">&quot;%d %lg %lg %lg %lg&quot;</span>,&amp;i,&amp;x,&amp;y,&amp;z,&amp;r))==5) <a class="code" href="classvoro_1_1pre__container__poly.html#abc5d9009deec44c1f5fc88e4da10e89a">put</a>(i,x,y,z,r);
<a name="l00208"></a>00208         <span class="keywordflow">if</span>(j!=EOF) voro_fatal_error(<span class="stringliteral">&quot;File import error&quot;</span>,<a class="code" href="config_8hh.html#a8de7f106cac2556a67bcc61bd364ed38">VOROPP_FILE_ERROR</a>);
<a name="l00209"></a>00209 }
<a name="l00210"></a>00210 <span class="comment"></span>
<a name="l00211"></a>00211 <span class="comment">/** Allocates a new chunk of memory for storing particles. */</span>
<a name="l00212"></a><a class="code" href="classvoro_1_1pre__container__base.html#a3b9e5b59a4fd8477321d9412feffac4f">00212</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container__base.html#a3b9e5b59a4fd8477321d9412feffac4f">pre_container_base::new_chunk</a>() {
<a name="l00213"></a>00213         <a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>++;<a class="code" href="classvoro_1_1pre__container__base.html#ae4dc10b744019a92efffbcc1ece189e4">end_p</a>++;
<a name="l00214"></a>00214         <span class="keywordflow">if</span>(<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>==<a class="code" href="classvoro_1_1pre__container__base.html#a49cb1c584f78ac8fdce353fd2f43b5f6">l_id</a>) <a class="code" href="classvoro_1_1pre__container__base.html#abc281e0f5b042046451b1d86ee94880d">extend_chunk_index</a>();
<a name="l00215"></a>00215         <a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>=*<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>=<span class="keyword">new</span> <span class="keywordtype">int</span>[pre_container_chunk_size];
<a name="l00216"></a>00216         <a class="code" href="classvoro_1_1pre__container__base.html#a73bcad154008325e074bea734fc4125b">e_id</a>=<a class="code" href="classvoro_1_1pre__container__base.html#a432897c62a5d0c1acc39a97ffe27b506">ch_id</a>+pre_container_chunk_size;
<a name="l00217"></a>00217         <a class="code" href="classvoro_1_1pre__container__base.html#abe6c99e9fa26d0764014c5f2913ed6c9">ch_p</a>=*<a class="code" href="classvoro_1_1pre__container__base.html#ae4dc10b744019a92efffbcc1ece189e4">end_p</a>=<span class="keyword">new</span> <span class="keywordtype">double</span>[<a class="code" href="classvoro_1_1pre__container__base.html#a4a3ff1d6bee289e53f5015327384444a">ps</a>*pre_container_chunk_size];
<a name="l00218"></a>00218 }
<a name="l00219"></a>00219 <span class="comment"></span>
<a name="l00220"></a>00220 <span class="comment">/** Extends the index of chunks. */</span>
<a name="l00221"></a><a class="code" href="classvoro_1_1pre__container__base.html#abc281e0f5b042046451b1d86ee94880d">00221</a> <span class="keywordtype">void</span> <a class="code" href="classvoro_1_1pre__container__base.html#abc281e0f5b042046451b1d86ee94880d">pre_container_base::extend_chunk_index</a>() {
<a name="l00222"></a>00222         <a class="code" href="classvoro_1_1pre__container__base.html#a9ae49ab1c51dc851e7ddf3035b719a6b">index_sz</a>&lt;&lt;=1;
<a name="l00223"></a>00223         <span class="keywordflow">if</span>(<a class="code" href="classvoro_1_1pre__container__base.html#a9ae49ab1c51dc851e7ddf3035b719a6b">index_sz</a>&gt;max_chunk_size)
<a name="l00224"></a>00224                 voro_fatal_error(<span class="stringliteral">&quot;Absolute memory limit on chunk index reached&quot;</span>,<a class="code" href="config_8hh.html#a5dc0616f8a67ae3d1c2ba8a3dcf5612b">VOROPP_MEMORY_ERROR</a>);
<a name="l00225"></a>00225 <span class="preprocessor">#if VOROPP_VERBOSE &gt;=2</span>
<a name="l00226"></a>00226 <span class="preprocessor"></span>        fprintf(stderr,<span class="stringliteral">&quot;Pre-container chunk index scaled up to %d\n&quot;</span>,<a class="code" href="classvoro_1_1pre__container__base.html#a9ae49ab1c51dc851e7ddf3035b719a6b">index_sz</a>);
<a name="l00227"></a>00227 <span class="preprocessor">#endif</span>
<a name="l00228"></a>00228 <span class="preprocessor"></span>        <span class="keywordtype">int</span> **n_id=<span class="keyword">new</span> <span class="keywordtype">int</span>*[<a class="code" href="classvoro_1_1pre__container__base.html#a9ae49ab1c51dc851e7ddf3035b719a6b">index_sz</a>],**p_id=n_id,**c_id=<a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>;
<a name="l00229"></a>00229         <span class="keywordtype">double</span> **n_p=<span class="keyword">new</span> <span class="keywordtype">double</span>*[<a class="code" href="classvoro_1_1pre__container__base.html#a9ae49ab1c51dc851e7ddf3035b719a6b">index_sz</a>],**p_p=n_p,**c_p=<a class="code" href="classvoro_1_1pre__container__base.html#a8f3fadf0d9d115fec92eedbcb2c5af9c">pre_p</a>;
<a name="l00230"></a>00230         <span class="keywordflow">while</span>(c_id&lt;<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>) {
<a name="l00231"></a>00231                 *(p_id++)=*(c_id++);
<a name="l00232"></a>00232                 *(p_p++)=*(c_p++);
<a name="l00233"></a>00233         }
<a name="l00234"></a>00234         <span class="keyword">delete</span> [] <a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>;<a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>=n_id;<a class="code" href="classvoro_1_1pre__container__base.html#a687bc9acac994d7918e1e34c27df68e3">end_id</a>=p_id;<a class="code" href="classvoro_1_1pre__container__base.html#a49cb1c584f78ac8fdce353fd2f43b5f6">l_id</a>=<a class="code" href="classvoro_1_1pre__container__base.html#a927440d3390000b94cce98733d81811c">pre_id</a>+<a class="code" href="classvoro_1_1pre__container__base.html#a9ae49ab1c51dc851e7ddf3035b719a6b">index_sz</a>;
<a name="l00235"></a>00235         <span class="keyword">delete</span> [] <a class="code" href="classvoro_1_1pre__container__base.html#a8f3fadf0d9d115fec92eedbcb2c5af9c">pre_p</a>;<a class="code" href="classvoro_1_1pre__container__base.html#a8f3fadf0d9d115fec92eedbcb2c5af9c">pre_p</a>=n_p;<a class="code" href="classvoro_1_1pre__container__base.html#ae4dc10b744019a92efffbcc1ece189e4">end_p</a>=p_p;
<a name="l00236"></a>00236 }
<a name="l00237"></a>00237 
<a name="l00238"></a>00238 }
</pre></div></div>
</div>


<hr class="footer"/><address class="footer"><small>
Generated on Fri Sep 23 2011 22:49:06 for Voro++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
